package net.tplusplus.utils;

import java.util.HashMap;
import java.util.Map;

public class TimedResults
{
	private long fastest = -1;
	private long slowest = -1;
	
	private Map<Long,Long> results = new HashMap<Long,Long>();
	
	public TimedResults()
	{
	}
	
	public void addTime(long time)
	throws Exception
	{
		if(time < 0)
		{
			throw new Exception("Invalid Time");
		}
		
		Long key = System.currentTimeMillis();
		results.put(key,time);
		
		if(fastest==-1 || fastest>time) fastest=time;
		if(slowest==-1 || slowest<time) slowest=time;
	}
	
	public Map<Long,Long> getResults()
	{
		return results;
	}
	
	public long getFastest()
	{
		return fastest;
	}
	
	public long getSlowest()
	{
		return slowest;
	}
	
	public long getAverage()
	{
		long time = 0;
		
		for(Long timetaken : results.values())
		{
			time += timetaken;
		}
		
		return time / results.size();
	}
}
